﻿namespace EyeSoft.Test.Net.NetworkInformation
{
	using System.Net.Sockets;

	using EyeSoft.Net.NetworkInformation;

	using Microsoft.VisualStudio.TestTools.UnitTesting;

	using SharpTestsEx;

	[TestClass]
	public class TcpPingTest
	{
		private const string CorrectDomain = "www.microsoft.com";
		private const string WrongDomain = "www.microsoft.com2";
		private const int TimeOut = 1000;
		private const int Port = 80;
		private const bool NotThrowOnError = false;
		private const bool ThrowOnError = true;

		[TestMethod]
		public void TryPingExistingDomainFalseOnError()
		{
			TcpPing.Send(CorrectDomain, Port, NotThrowOnError, TimeOut).Should().Be.True();
		}

		[TestMethod]
		public void TryPingWrongDomainFalseOnError()
		{
			TcpPing.Send(WrongDomain, Port, NotThrowOnError, TimeOut).Should().Be.False();
		}

		[TestMethod]
		public void TryPingExistingDomainExceptionOnError()
		{
			TcpPing.Send(CorrectDomain, Port, ThrowOnError, TimeOut).Should().Be.True();
		}

		[TestMethod]
		public void TryPingWrongDomainExceptionOnError()
		{
			Executing.This(() => TcpPing.Send(WrongDomain, Port, ThrowOnError, TimeOut))
				.Should().Throw<SocketException>()
				.And.Exception.ErrorCode.Should()
				.Be.EqualTo(11003);
		}
	}
}